<template>
  <div class="app-container">
    <el-row type="flex" align="center" :gutter="20">
      <el-form class="filterData-block" label-position="left" :inline="true" label-width="auto">
        <el-form-item label="关键字:">
          <el-input
            placeholder="标题 | 公司 | 描述"
            v-model="filterData.keyword"
            maxlength="20"
            size="small"
            clearable
          >
          </el-input>
        </el-form-item>
        <el-form-item label="审核状态:">
          <el-cascader
            v-model="filterData.state"
            clearable
            placeholder="全部状态"
            :options="trainTypeOption"
            size="small"
            :props="{value:'id',label:'data'}"
            filterDataable
          ></el-cascader>
        </el-form-item>
        <el-form-item label="发布时间:">
          <el-date-picker
            v-model="filterData.time"
            value-format="yyyy-MM-dd HH:mm:ss"
            size="small"
            clearable
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            align="left"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button size="small" icon="el-icon-search" type="primary" @click="refreshTable">搜索</el-button>
        </el-form-item>
      </el-form>
    </el-row>
    <el-row style="margin-top: 20px">
      <el-table v-loading="tableConf.loading" :stripe="true" :border="true" :data="tableData">
        <el-table-column align="center" width="50px" prop="id" label="ID"/>
        <el-table-column align="center" min-width="100px" prop="jobTitle" label="标题"/>
        <el-table-column align="center" min-width="100px" prop="jobName" label="行业"/>

        <el-table-column align="center" label="所属公司所属公司" width="200px">
          <template  slot-scope="{row}">
            <div style="cursor: pointer;" @click="openDetail(row.enterprise.id,2)">{{row.enterprise.enterpriseName}}</div>
          </template>
        </el-table-column>
        <el-table-column align="center" min-width="100px" prop="crtTimeText" label="发布时间"/>
        <el-table-column align="center" min-width="100px"  label="审核状态">
          <template slot-scope="{row}">
            {{row.recruitStateText}}
            <template v-if="row.recruitState===2">
              ({{row.remarks}})
            </template>
          </template>
        </el-table-column>
        <el-table-column align="center" width="260px" label="操作">
          <template slot-scope="{row}">
            <el-button size="mini" icon="el-icon-check" type="primary" v-if="row.recruitState===1" @click="updateRowState(row.id,3)">通过
            </el-button>
            <el-button size="mini" icon="el-icon-close" type="primary" v-if="row.recruitState===1" @click="openDetail(row.id,0)">拒绝
            </el-button>
            <el-button size="mini" icon="el-icon-search" type="primary" @click="openDetails(row.id)">详情
            </el-button>

          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <el-row style="margin-top: 20px">
      <el-pagination
        :page-sizes="tableConf.sizes"
        :page-size="tableConf.size"
        :total="tableConf.total"
        :current-page="tableConf.page"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-row>
    <el-dialog width="50%"  v-if="visible[0]" :visible.sync="visible[0]" title="拒绝理由" :close-on-click-modal="false"
               :close-on-press-escape="false" :destroy-on-close="true"
    >
      <PositionCodeDetail ref="detail" :id="detailId" :closeDialog="closeDialog"></PositionCodeDetail>
      <span slot="footer" class="dialog-footer">
        <el-button plain type="primary" @click="visible[0] = false">取 消</el-button>
        <el-button type="primary" class="primary" @click="$refs.detail.submit()">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog width="50%"  v-if="visible[1]" :visible.sync="visible[1]" title="岗位详情" :close-on-click-modal="false"
               :close-on-press-escape="false" :destroy-on-close="true"
    >
      <PositionCodeDetails ref="detail" :id="detailId" :closeDialog="closeDialog"></PositionCodeDetails>
      <span slot="footer" class="dialog-footer">
        <el-button plain type="primary" @click="visible[1] = false">取 消</el-button>
        <el-button type="primary" class="primary" @click="visible[1] = false">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog width="50%"  v-if="visible[2]" :visible.sync="visible[2]" title="详情" :close-on-click-modal="false" top="0"
               :close-on-press-escape="false" :destroy-on-close="true"
    >
      <ComDetails ref="detail1" :id="detailId" :closeDialog="closeDialog"></ComDetails>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" class="primary" @click="visible[2] = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import PositionCodeDetail from '@/components/PositionCode/Detail'
import PositionCodeDetails from '@/components/PositionCode/Details'
import ComDetails from '@/components/PersonnelCode/comDetails';
import {getTrainStateApi} from '@/api/trainCode'
import {getPublishListByModelApi, toExaminePublishApi} from "@/api/companyCode";

export default {
  components: { PositionCodeDetail,PositionCodeDetails,ComDetails },
  data() {
    return {
      tableData: [],
      tableConf: {
        page: 1,
        sizes: [10, 20, 50, 100],
        total: 0,
        size: 10,
        loading: false
      },
      visible: {//控制弹窗显示
        0: false,
        1: false,
        2: false
      },
      detailId: null,
      keyword: '',//关键字查询
      filterData: {
        keyword: '',
        state: [],
        time: []
      },
      placeTypeLoading: true,
      trainTypeOption: [
        {id: 1,data: "待审核"},
        {id: 2,data: "未通过"},
        {id: 3,data: "开放中"},
        {id: 4,data: "关闭中"},

      ]

    }
  },
  mounted() {
    this.getTableList()
  },
  methods: {
    downloadCode(url) {
      window.open(url)
    },
    updateRowState(id,stateType) {
      toExaminePublishApi({ id, stateType }).then(() => {
        this.$message.success('修改成功')
      }).finally(() => {
        this.getTableList()
      })
    },
    //扫码记录
    openRecord(id) {
      //新标签页打开列表
      this.$router.push({
        name: 'PlaceScanRecord',
        query: {
          id: id
        }
      })
    },
    //打开添加/编辑页
    openDetail(id = null,index) {
      this.detailId = id
      this.visible[index] = true
    },
    openDetails(id) {
      this.detailId = id
      this.visible[1] = true
    },
    //关闭指定弹窗并刷新页面
    closeDialog(index) {
      this.visible[index] = false
      this.getTableList()
    },
    // 每页显示数量change
    handleSizeChange(e) {
      this.tableConf.size = e
      this.getTableList()
    },
    // 当前页change
    handleCurrentChange(e) {
      this.tableConf.page = e
      this.getTableList()
    },
    //获取列表
    getTableList() {
      this.tableConf.loading = true
      const state = this.filterData.state.length === 0 ? 0 : this.filterData.state[0];
      let startTime = "";
      let endTime = "";
      if(this.filterData.time!=null)
      {
        startTime = this.filterData.time[0];
        endTime = this.filterData.time[1];
      }
      getPublishListByModelApi({
        orderDate: 3,
        page: this.tableConf.page,
        limit: this.tableConf.size,
        keyWord: this.filterData.keyword,
        state,
        startTime: startTime,
        endTime: endTime
      }).then((res) => {
        console.log(res)
        this.tableData = res.list
        this.tableConf.total = res.count
      }).finally(() => {
        this.tableConf.loading = false
      })
    },
    refreshTable() {
      this.tableConf.page = 1
      this.getTableList()
    }
  }
}
</script>
<style lang="scss" scoped>
.filterData-block {
  .el-form-item {
    margin-bottom: 0;
  }
}
</style>
